package com.learning.hadoop.mapreduce.join;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;


/**
 * 订单表：
 * id	date	    pid	   amount
 * 1001	20150710	P0001	2
 * 1002	20150710	P0001	3
 * 1002	20150710	P0001	3
 * <p>
 * 商品信息表 product.txt
 * id	pName	categoryId	price
 * P0001	小米5	1001	2
 * P0002	锤子T1	1000	3
 * P0003	锤子	    1002	3
 *
 * @author Sam Sho
 */
public class InfoBean implements Writable {
    private String orderId;
    private String date;
    private String pid;
    private int amount;
    private String pName;
    private String categoryId;
    private float price;
    // flag=0表示这个对象是封装订单表记录
    // flag=1表示这个对象是封装产品信息记录
    private String flag;

    public void set(String orderId, String date, String pid, int amount, String pname,
                    String categoryId, float price, String flag) {
        this.orderId = orderId;
        this.date = date;
        this.pid = pid;
        this.amount = amount;
        this.pName = pname;
        this.categoryId = categoryId;
        this.price = price;
        this.flag = flag;
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getPid() {
        return pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public String getPName() {
        return pName;
    }

    public void setPName(String pName) {
        this.pName = pName;
    }

    public String getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(String categoryId) {
        this.categoryId = categoryId;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    public String getFlag() {
        return flag;
    }

    public void setFlag(String flag) {
        this.flag = flag;
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.orderId = in.readUTF();
        this.date = in.readUTF();
        this.pid = in.readUTF();
        this.amount = in.readInt();
        this.pName = in.readUTF();
        this.categoryId = in.readUTF();
        this.price = in.readFloat();
        this.flag = in.readUTF();
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(orderId);
        out.writeUTF(date);
        out.writeUTF(pid);
        out.writeInt(amount);
        out.writeUTF(pName);
        out.writeUTF(categoryId);
        out.writeFloat(price);
        out.writeUTF(flag);
    }

    @Override
    public String toString() {
        return "orderId=" + orderId + ", date=" + date + ", pid=" + pid + ", amount=" + amount + ", pName="
                + pName + ", categoryId=" + categoryId + ", price=" + price;
    }


}